<?php
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
global $_G;

$out_biz_no = daddslashes($_GET['out_biz_no']);
if(!$out_biz_no) {
	showmessage('payment_order_no_exist', '', array(), array('showdialog' => true));
}

$order = C::t('common_payment_order')->fetch_by_biz_no($out_biz_no);
if(!$order || $order['expire_time'] < time()) {
	showmessage('payment_order_no_exist', '', array(), array('showdialog' => true));
}
if($order['status']) {
	showmessage('payment_succeed', '', array(), array('showdialog' => true));
}
$order_id = $order['id'];

$pay_channel = daddslashes($_GET['pay_channel']);
$payclass = payment::get($pay_channel);
if(!$payclass) {
	showmessage('payment_type_no_exist', $_G['siteurl'] . 'home.php?mod=spacecp&ac=payment&op=pay&order_id=' . $order_id, array(), array('showdialog' => true, 'locationtime' => 3));
}

$result = $payclass->pay($order);
if($result['code'] != 200) {
	showmessage($result['message'], $_G['siteurl'] . 'home.php?mod=spacecp&ac=payment&op=pay&order_id=' . $order_id, array(), array('showdialog' => true, 'locationtime' => 3));
}
$type = $result['type'];
$pay_url = $result['url'];
$money = sprintf('%.2f', $order['amount']/100);
$channel_name = lang('plugin/unifiedpay', 'payment_'.$pay_channel);

if($type == 'wxjspay') {
	$jsapidata = $pay_url;
	$mode = isset($_GET['mode']) ? intval($_GET['mode']) : 0;
	if($mode == 1) {
		include template('home/spacecp_payment_wxjsapi');
	}else{
		include template('unifiedpay:wxjspay');
	}
}elseif($type == 'html') {
	include template('unifiedpay:pagepay');
}else{
	include template('unifiedpay:payment_redirect');
}